package com.shortvedio.content.api;

import com.shortvedio.base.context.BaseContext;
import com.shortvedio.base.model.Result;
import com.shortvedio.base.model.po.Classify;
import com.shortvedio.content.service.ClassifyService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/label")
public class LabelController {

    @Autowired
    private ClassifyService classifyService;


    @PostMapping("add_classify")   //添加分类
    public Result addClassify(@RequestBody Classify classify){
        Long userId = BaseContext.getCurrentId();
        classify.setUserId(userId);
        Result result = classifyService.addClassify(classify);
        return result;
    }

    @DeleteMapping("delet_classify")  //删除分类
    public Result deletClassify(@RequestParam Long classifyId){
        Long userId = BaseContext.getCurrentId();
        Result result = null;
        try {
            result = classifyService.deleteClassify(classifyId,userId);
        } catch (IOException e) {
            return Result.error("删除失败");
        }
        return result;
    }

    @PostMapping("add_user_interest")
    public Result addUserInterest(@RequestParam Long classifyId){
        Long userId = BaseContext.getCurrentId();
        Result result = classifyService.addUserInterest(userId, classifyId);
        return result;
    }

}
